<template>
	<view class=" beijingse">
		<view class="margin_top huanbox flexbetween mainpadding">
			<view class="ershil xiaocheng">需购：
				<text class="titletext xiaocheng nofonweight">{{dataAll.xg_price}}</text>
			</view>
			<view class="ershil xiaocheng">已购：
				<text class="titletext xiaocheng fonweight">{{dataAll.yg_price}}</text>
			</view>
			<view class="ershil xiaocheng">需补：
				<text class="titletext xiaocheng fonweight">{{dataAll.xb_price}}</text>
			</view>
		</view>
		<view class="mainpadding2">
			<view class="ffffff boxbai flexbetween margin_top dingwei" v-for="item in dataAll.goodsdata" :key="item.id" @click="tzsoxq(item.id)">
				<image class="sptp" :src="item.image_text" mode=""></image>
				<view class="" style="width: 71%;">
					<view class="ershiba xiaohei margin_top1">{{item.name}}</view>
					<view class="flexbetween margin_top2">
						<view class="titletext xiaocheng fonweight ">￥{{item.price}}</view>
						<view class="ershil xiaocheng fonweight ">x{{item.number}}</view>
					</view>
				</view>
				<view class="shanbox flexcenter" @click.stop="deleteitem(item.id)">
					<u-icon name="trash" color="#FF0000" size="18"></u-icon>
				</view>
			</view>
		</view>
		<view class="mainpadding gudingdb">
			<view class="dibox flexbetween">
				<view class="flexleft">
					<view class="dingwei margin_right3">
						<image class="heji " src="../static/image/system/hj.png" mode=""></image>
						<view class="huasuz flexcenter">{{allnum}}</view>
					</view>
					<view class="line margin_right3"></view>
					<view class="bigtext xiaohei ">合计
						<text class="bigtext xiaocheng fonweight">￥{{dataAll.allsub}}</text>
					</view>
				</view>
				<view class="qdbtn flexcenter" @click="buy">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				user_level_id: "",
				gwcList: [],
				dataAll:{},
				allnum:0
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.gwcList = data.data
			this.user_level_id = data.user_level_id
			console.log(this.gwcList,"惊雷");
			this.init()
		},
		methods: {
			getnumber(){
				let number = 0
				console.log(this.gwcList,"惊雷2");
				this.dataAll.goodsdata.forEach(item=>{
					number = Number(item.number)+ Number(number)
				})
				this.allnum = number
			},
			
			init() {
				let _this = this
				let data = []
				this.gwcList.forEach(item=>{
					data.push({
						goods_id:item.id,
						number:item.number
					})
				})
				httpRequest.request('/api/order/getUserOrderData', 'POST', {
					user_level_id:this.user_level_id,
					data
				}).then(res => {
					this.dataAll = res.data
					this.getnumber()
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			buy(){
				let data = {
					type: "", //detail=商品详情,cart=购物车
					ly:4,//1=普通商品,2=换货,3=复购专区,4=会员购买
					data: [],
					user_level_id:this.user_level_id
				}
				let num = 0
				this.dataAll.goodsdata.forEach(item => {
					data.data.push({
						goods_id: item.id,
						number: item.number,
					})
					num = num + 1
				})
				if (num == 0) {
					httpRequest.toast("请选择商品")
					return
				}
				uni.navigateTo({
					url: '/pages_homepage/querendd?msg=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			deleteitem(id){
				this.gwcList.forEach((item,index)=>{
					if(item.id==id){
						this.gwcList.splice(index,1)
					}
				})
				uni.$emit("changegwcList",this.gwcList)
				this.init()
				this.getnumber()
			},
			// 跳转购物车详情
			tzsoxq(id) {
				uni.navigateTo({
					url: '/pages_homepage/shangpinxq?ly=4&id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shanbox {
		position: absolute;
		top: 0;
		right: 0;
		width: 107rpx;
		height: 40rpx;
		background: rgba(255, 0, 0, 0.1);
		border-radius: 0rpx 14rpx 0rpx 14rpx;
	}

	.huanbox {
		border-bottom: 1rpx solid #FF9341;
		border-top: 1rpx solid #FF9341;
		background: rgba(255, 147, 65, 0.1);
	}

	.qdbtn {
		width: 193rpx;
		height: 75rpx;
		background: linear-gradient(85deg, #FFB67F 0%, #FF9341 100%);
		border-radius: 52rpx 52rpx 52rpx 52rpx;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.line {
		width: 2rpx;
		height: 42rpx;
		background-color: #D8D8D8;
	}

	.huasuz {
		position: absolute;
		top: -3rpx;
		right: -13rpx;
		width: 27rpx;
		height: 27rpx;
		background: #FF9341;
		border-radius: 50%;
		font-size: 17rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.heji {
		width: 37.5rpx;
		height: 39.58rpx;
	}

	.dibox {
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.05);
		border-radius: 53rpx 53rpx 53rpx 53rpx;
		padding: 13rpx 13rpx 13rpx 41rpx;
	}

	.sptp {
		width: 157rpx;
		height: 157rpx;
		border-radius: 14rpx;
	}

	//结束
	.boxbai {
		padding: 30rpx;
		border-radius: 11rpx;
	}
</style>